#include "Graph.h"
#include "UniFind.h"
#include <queue>

queue<GraphEdge*> Kruskal(Graph* g)
{
    int *unifArr = Create_UniFSet(g->nodeSet.size());
    priority_queue<GraphEdge *, vector<GraphEdge *>, EdgeCmp> edgeSet;
    for(auto e : g->edgeSet)
    {
        edgeSet.push(e);
    }
    queue<GraphEdge *> result;
    while(!edgeSet.empty())
    {
        auto e = edgeSet.top();
        edgeSet.pop();
        if(Merge(unifArr, e->from->value, e->to->value))
        {
            result.push(e);
        }
    }
    return result;
}